/* It gives first derivative at the points "xderv". It is not necessary that these points
   must lie within the points "x". Instead, these can be "anywhere". */

# include "scene.h"
# include <stdlib.h>

extern short cmtrx_interpol(double *x, unsigned short nxpt, double *xipl, unsigned short nxiplpt,\
 unsigned short norder, double **mtrx);

extern short cmtrx_make(double **mtrx, unsigned short nrows, unsigned short ncols, struct cmtrx *cm);

extern short cmtrx_1dim_interpol(double *x, unsigned short nxpt, double *xipl, unsigned short nxiplpt,\
 struct cmtrx *cm, double **tempmtrx)
 {
  double **mtrx;
  unsigned short i;
  short ecode = 1;

  if(tempmtrx != (double **)0) mtrx = tempmtrx;
  else{
       mtrx = (double **)malloc(sizeof(double *)*nxiplpt);
       for(i = 0; i < nxiplpt; i++) mtrx[i] = (double *)malloc(sizeof(double)*nxpt);
      }

  ecode = cmtrx_interpol(x, nxpt, xipl, nxiplpt, cm->napprox, mtrx);

  if(ecode > 0) ecode = cmtrx_make(mtrx, nxiplpt, nxpt, cm);

  if(tempmtrx == (double **)0)
     {
      for(i = 0; i < nxiplpt; i++) free(mtrx[i]);
      free(mtrx);
     }

  return ecode;
 }
